オペレーティングシステム3-A 200303449 情報 大柴慶一write1.c #include fcntl.h #include stdio.h #include time.h int main() { int fd; char s[50]; time_t t; int i, j, n = 1, maxprime = 3; int max = 100000; /*** time stamp1 here ***/ t = time(NULL); printf("Start time: %s", ctime(&t)); fd = open("file1", O_CREAT | O_TRUNC | O_WRONLY, 0664); while (1) { printf(" "); fgets(s, 50, stdin); // get string if (s[0] == '\n') break; /*** Big processing here ***/ for (i = 3; i <= max; i = i + 2) { for (j = 3; (i - (i / j) * j) != 0; j++); if (i == j) { n++; maxprime = i; } } write(fd, s, sizeof(s));//write string to file } /*** time stamp2 here ***/ t = time(NULL); printf("End time: %s", ctime(&t)); close(fd); } 結果 [s033449@kanagawa-info s033449]$ ./a.out Start time: Thu Jun 23 15:09:48 2005 keiichi oshiba kazuyo sekio kazuhito naoya saki aa abc ewing End time: Thu Jun 23 15:12:43 2005 [s033449@kanagawa-info s033449]$ gcc read1.c [s033449@kanagawa-info s033449]$ ./a.out keiichi oshiba kazuyo sekio kazuhito naoya saki aa abc ewing |